data "aws_vpc" "main" {
  filter {
    name   = "tag:Name"
    values = ["app2"]  # 使用与创建 VPC 相同的名称查找
  }
}

data "aws_subnets" "main" {
  filter {
    name   = "vpc-id"
    values = [data.aws_vpc.main.id]  # 使用查找到的 VPC ID
  }
}

data "aws_security_group" "sg" {
  filter {
    name   = "tag:Name"
    values = ["web-sg"]  # 使用与创建 VPC 相同的名称查找
  }
}

data "aws_lb_target_group" "this" {
    name   = "example-tg"
}


module "ec2" {
  source        = "../../modules/ec2"
  instance_count         = 2
  ami           = "ami-07c9c7aaab42cba5a"
  instance_type = "t2.micro"
  security_groups  = [data.aws_security_group.sg.id]
  target_group_arn = data.aws_lb_target_group.this.arn
  subnet_ids      = data.aws_subnets.main.ids
#  subnet_id     = module.network.subnet_id
#  volume_id     = aws_ebs_volume.example[count.index].id
}
